Menu
[TOC]
T-SQL : Query under Conditions
Main Frame
The basic searching code is under such format, A select
--from
--where
is the most basic structure in a query.
select A,B,C,,Z
from R1,R2,...,Rn
where F
which can be transformed into :
Thus , select
means , and where means .
If there's no limitation , means you want to get all the information from single table :
select * from TABLENAME
here , *
means no limitation. or you can replace from distinct
, which means canceling same tuples.
behind where
you can put bool calculation , and it will select with the answer is true.
All in all , the main structure of SELECT Query is :
SELECT select_list [INTO new_table]
[FROM table_source] [WHERE search_condition]
[GROUP BY group_by_expression]--Regroup the result by condition, each group generate a single tuple in result table.
[HAVING search_condition]
[ORDER BY order_expression[ASC | DESC]]
[Notice] A single select block can be nested for another select block.
Inner function
count([distinct|all] expression)
Return the number of elements which is not null.
sum(expression)
Plus every elements together and return the result.
avg(expression)
Return the average
max()
andmin()
Additional commend
//TODO
order by :